import React, { Component,createRef } from 'react';

class LoadMore extends Component {
    constructor(props){
        super(props)
        this.load = createRef()
    }
    componentDidMount(){
        let timer =null
        let clientHeight = document.documentElement.clientHeight;
        let that = this
        window.onscroll = function(){
            let domTop = that.load.current.getBoundingClientRect().top
            if(timer){
                clearTimeout(timer)
            }
            timer = setTimeout(()=>{
                if(domTop < clientHeight){
                   that.props.loadMoreHandler()
                }
            },300)
            
        }
    }
    componentWillUnmount(){
        window.onscroll = null
    }
    render() {
        return (
          <div ref={this.load}>
            加载更多 
         </div>
            
        );
    }
}

export default LoadMore;